// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 2010-6-14 20:31:01
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   DateFormatter.java

package com.brother.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class DateFormatter
{

    public DateFormatter()
    {
    }

    public void setConfig(String hourOffSet, String pattern)
    {
        format = new SimpleDateFormat(pattern);
        int customer = (int)(Float.parseFloat(hourOffSet) * 60 * 60 * 1000);
        format.getTimeZone().setRawOffset(customer);
    }

    public String format(Date date)
    {
        return format.format(date);
    }

    public static boolean isChineaseFormat(String date)
    {
        if(date == null)
            return false;
        return date.split("-")[0].length() == 4;
    }

    public static String zhToEn(String date)
    {
        if(date == null)
            return null;
        if(isChineaseFormat(date))
        {
            String dates[] = date.split(" ");
            String year[] = dates[0].split("-");
            if(dates.length > 1)
                return (new StringBuilder(String.valueOf(year[1]))).append("/").append(year[2]).append("/").append(year[0]).append(" ").append(dates[1]).toString();
            else
                return (new StringBuilder(String.valueOf(year[1]))).append("/").append(year[2]).append("/").append(year[0]).toString();
        } else
        {
            return date;
        }
    }

    public static String enToZh(String date)
    {
        if(date == null)
            return null;
        if(!isChineaseFormat(date))
        {
            String dates[] = date.split(" ");
            String year[] = dates[0].split("-");
            if(dates.length > 1)
                return (new StringBuilder(String.valueOf(year[2]))).append("-").append(year[0]).append("-").append(year[1]).append(" ").append(dates[1]).toString();
            else
                return (new StringBuilder(String.valueOf(year[2]))).append("-").append(year[0]).append("-").append(year[1]).toString();
        } else
        {
            return date;
        }
    }

    public static String toEastEight(Date date, String offset, String pattern)
    {
        float timezone = 8 - Float.parseFloat(offset);
        date.setHours((int)(date.getHours() + timezone));
        date.setMinutes(date.getMinutes() + (int)((timezone - (int)timezone) * 60));
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        return format.format(date);
    }

    private SimpleDateFormat format;
}